package cn.panda.edu.controller;

import cn.panda.edu.model.Score;
import cn.panda.edu.service.ScoreService;
import cn.panda.edu.util.Constant;
import cn.panda.edu.util.ResultDataUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * 类描述：  成绩表的Controller
 * @author: 张坤鹏  
 * @date： 2018-01-16 下午12:19:49
 */
@RestController
@RequestMapping("/api/teacher/score")
public class TeacherScoreController {
	
	final int PAGESIZE=10;
	@Autowired
	private ScoreService sconreservice;

	
	@ApiOperation(value="获取成绩信息列表",notes="")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageIndex", value = "当前页数", required = true, dataType = "Integer"),
		@ApiImplicitParam(name = "id", value = "学生id", required = false, dataType = "Integer"),
		@ApiImplicitParam(name = "name", value = "学生名字", required = false, dataType = "String"),
	})
	@RequestMapping(value="/getAllListScore",method=RequestMethod.POST)
	public  Object getAllListScore(Integer pageIndex,Integer id,String name){
		if(pageIndex == null){
			pageIndex=1;	
		}
		PageInfo<Score> pageInfo=sconreservice.getAllListScore(pageIndex,Constant.PAGE_SIZE,id,name);
		return ResultDataUtil.resData(200, "", pageInfo);
	}
	
	
	@ApiOperation(value="修改成绩",notes="")
	@RequestMapping(value="/updateByPrimaryKey/{id}",method=RequestMethod.POST)
	public Object updateByPrimaryKey(Score record){
		int status=200;
		String message=null;
		int i = sconreservice.updateByPrimaryKeySelective(record);
		if(i>0){
			status=200;
			message="添加成功!";
		}else {
			status=500;
			message="添加失败!";
		}
		return ResultDataUtil.resData(status, message, null);
	}
	
	@ApiOperation(value="添加成绩",notes="")
	@RequestMapping(value="/insertSelective",method=RequestMethod.POST)
	public Object insertSelective(Score record) {
		int status=200;
		String message=null;
		int i = sconreservice.insertSelective(record);
		if(i>0){
			status=200;
			message="添加成功!";
		}else {
			status=500;
			message="添加失败!";
		}
		return ResultDataUtil.resData(status, message, null);
	}
	
	
}
